package com.hsgene.common;

import com.hsgene.common.util.exception.IllegalParamException;

/**
 * 客户端类型
 *
 * @author wangbing
 * @version 1.0, 2018/10/15
 */
public enum ClientType {

    /**
     * 运营后台
     */
    CONSOLE(1, "运营后台"),

    /**
     * 花生仁
     */
    PEANUT(2, "花生仁"),

    /**
     * 金琉璃
     */
    GOLD_COLORED_GLASS(3, "金琉璃"),

    /**
     * 小程序
     */
    APPLETS(4, "因子网小程序"),

    /**
     * pc端
     */
    PC(5, "因子网PC端"),

    /**
     * APP
     */
    APP(6, "因子网APP");

    private Integer code;

    private final String identifier;

    ClientType(Integer code, String identifier) {
        this.code = code;
        this.identifier = identifier;
    }

 /*   public static ClientType getEnum(String identifier) {
        for (ClientType type : values()) {
            if (type.identifier.equalsIgnoreCase(identifier)) {
                return type;
            }
        }
        throw new IllegalParamException("非法的客户端类型参数：" + identifier);
    }*/

    public static ClientType getEnum(Integer code) {
        for (ClientType type : values()) {
            if (type.code.equals(code)) {
                return type;
            }
        }
        throw new IllegalParamException("非法的客户端类型参数：" + code);
    }

    /**
     * 是否来自于商城
     *
     * @return true：是；false：不是
     */
    public boolean isGeneShop() {
        return this.equals(APPLETS) || this.equals(APP) || this.equals(PC);
    }

    public String getIdentifier() {

        return identifier;
    }

    public Integer getCode() {
        return code;
    }
}
